/***
 * A collection of Expedition pile
 * 
 */
package it.stessaro.lostcities.collection;
import it.stessaro.lostcities.collection.pile.ColorPile;
import it.stessaro.lostcities.core.Costants;
import java.util.ArrayList;
import java.util.List;

public class ExpeditionPiles extends ArrayList<ColorPile>{

	private static final long serialVersionUID = 1L;
	private List<Card> playedCards;
	private List<Card> topCards;

	public ExpeditionPiles(){
		playedCards = new ArrayList<Card>();
		topCards = new ArrayList<Card>();
		this.add(Costants.RED, new ColorPile(Costants.RED));
		this.add(Costants.WHITE, new ColorPile(Costants.WHITE));
		this.add(Costants.GREEN, new ColorPile(Costants.GREEN));
		this.add(Costants.BLUE, new ColorPile(Costants.BLUE));
		this.add(Costants.YELLOW, new ColorPile(Costants.YELLOW));
	}

	public boolean addCard(Card card){
		int pos = card.getCardColor();
		if (card.getCardValue() >= this.get(pos).lastNumber()) {
			this.get(pos).addCard(card);
			playedCards.add(card);
			return true;
		}
		return false;
	}
	
	public boolean isCardPlayable(Card card){
		int pos = card.getCardColor();
		if (card.getCardValue() >= this.get(pos).lastNumber()) {
			return true;
		}
		return false;
	}
	
	
	public List<Card> getTopCards(){
		for (ColorPile expedition : this) {
			topCards.add(expedition.lastCard());
		}
		return topCards;
	}
	
	public String getMax(){
		String max = new String();
		int m = 0;
		for (ColorPile expedition : this) {
			if (expedition.value() > m) {
				max = expedition.getColorString();
				m = expedition.value();
			}
		}
		return max;
	}
	
	public int getPoint(int pos){
		int lista[] = new int[5];
		for (ColorPile expedition : this) {
			lista[expedition.getColor()] = expedition.value();
		}
		return lista[pos];
	}
	
	public int getScore(){
		int total = 0;
		for (ColorPile expedition : this) {
			total = total + expedition.value();
		}
		return total;
	}
}